﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DAO
{
    public static class KhachHangDAO
    {
        public static QL_HuongRungEntities db = new QL_HuongRungEntities();
        public static List<KHACHHANG> layDSKH()
        {
            List<KHACHHANG> arrKH = db.KHACHHANG.ToList();
            return arrKH;
        }

        public static KHACHHANG layKH(int maKH)
        {
            KHACHHANG kh =  db.KHACHHANG.Find(maKH);
            return kh;
        }

        public static void ThemKhachHang(KHACHHANG kh)
        {
            db.KHACHHANG.Add(kh);
            db.SaveChanges();
        }
        public static void CapNhatKhachHang(KHACHHANG kh)
        {
            var khachhang = db.KHACHHANG.Where(k => k.MaKH == kh.MaKH).FirstOrDefault();
            khachhang.TenKH = kh.TenKH;
            khachhang.DiaChi = kh.DiaChi;
            khachhang.SoDienThoai = kh.SoDienThoai;
            khachhang.DiemTichLuy = kh.DiemTichLuy;
            db.SaveChanges();
        }

        public static bool capNhatDiemTichLuy(KHACHHANG kh)
        {
            try
            {
                KHACHHANG temp = db.KHACHHANG.Find(kh.MaKH);
                temp.DiemTichLuy = kh.DiemTichLuy;
                db.SaveChanges();
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

    }
}
